﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.EsbService;
using System.Threading;
using DEsbInterface;
using A2DFramework.InstanceService;

namespace DEsbConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Sending console");

            userBroker = EsbFactory.Create<IUser>();
            adminBroker = EsbFactory.Create<IAdmin>();

            //adminBroker.CheckPermission(DateTime.Now.Second.ToString(), DateTime.Now.Second).ToString();
            //userBroker.GetUserName("ThreadId: " + Thread.CurrentThread.ManagedThreadId, "", DateTime.Now.ToString());

            List<BatchSender> senders = new List<BatchSender>();
            for (var i = 0; i < 10; i++)
            {
                BatchSender sender = new BatchSender();
                sender.Setup(userBroker, adminBroker);
                senders.Add(sender);
            }

            senders.ForEach(t =>
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(t.Send));
            });
            Console.WriteLine("set done.");


            //while (true)
            //{
            //    //for (var i = 0; i < 30;i++ )
            //    //    ThreadPool.QueueUserWorkItem(new WaitCallback(SendRequest), i.ToString());

            //    SendRequest(DateTime.Now.ToString());

            //    Console.WriteLine("done.");
            //    //Thread.Sleep(200);
            //}
            Console.ReadKey();
        }

        private static IUser userBroker;
        private static IAdmin adminBroker;

        //private static void SendRequest(object state)
        //{
        //    string id = (string)state;
        //    string result = userBroker.GetUserName("id: "+id, "2", DateTime.Now.ToString());
        //    //Console.WriteLine("SendRequest ..."+id);
        //}
    }
}
